package shuanfa.sort;

import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;

/**
 * 冒泡排序
 */
public class BubbleSort {
    public static void main(String[] args) {
        int[] arr=new int[]{3,4,6,7,2,7,2,8,0};
        int[] array = new int[80000];
        for (int i = 0; i < 80000; i++) {
            array[i]=(int)(Math.random()*80000);
        }
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss");
        String format = simpleDateFormat.format(new Date());
        System.out.println("排序前时间：" + format);

        bubbleSort(arr);
        System.out.println(Arrays.toString(arr));
        String format1 = simpleDateFormat.format(new Date());
        System.out.println("排序后的时间：" + format1);
    }
    public static void bubbleSort(int[] array){
        for (int i = 0; i < array.length -1; i++) {
            for (int j = 0;j<array.length - i -1;j++){
                if (array[j] > array[j+1]){
                    int temp = array[j + 1];
                    array[j+1]=array[j];
                    array[j] = temp;
                }
            }
        }
    }
}
